package com.mercury.ec.module.air.dal.mysql.demandorder;

import com.mercury.ec.framework.common.pojo.PageResult;
import com.mercury.ec.framework.mybatis.core.mapper.BaseMapperX;
import com.mercury.ec.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.mercury.ec.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.mercury.ec.module.air.controller.admin.demandorder.vo.demandroutesegment.AirDemandRouteSegmentPageReqVO;
import com.mercury.ec.module.air.controller.admin.demandorder.vo.demandroutesegment.AirDemandRouteSegmentRespVO;
import com.mercury.ec.module.air.dal.dataobject.demandorder.AirDemandRouteSegmentDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 机票需求订单方案行程航段 Mapper
 *
 * @author hesx
 */
@Mapper
public interface AirDemandRouteSegmentMapper extends BaseMapperX<AirDemandRouteSegmentDO> {

    default PageResult<AirDemandRouteSegmentDO> selectPage(AirDemandRouteSegmentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AirDemandRouteSegmentDO>()
                .eqIfPresent(AirDemandRouteSegmentDO::getDemandId, reqVO.getDemandId())
                .eqIfPresent(AirDemandRouteSegmentDO::getDemandSchemeId, reqVO.getDemandSchemeId())
                .eqIfPresent(AirDemandRouteSegmentDO::getDemandRouteId, reqVO.getDemandRouteId())
                .eqIfPresent(AirDemandRouteSegmentDO::getSerialNo, reqVO.getSerialNo())
                .likeIfPresent(AirDemandRouteSegmentDO::getAirlineNo, reqVO.getAirlineNo())
                .likeIfPresent(AirDemandRouteSegmentDO::getFlightNo, reqVO.getFlightNo())
                .likeIfPresent(AirDemandRouteSegmentDO::getCabin, reqVO.getCabin())
                .likeIfPresent(AirDemandRouteSegmentDO::getDepart, reqVO.getDepart())
                .likeIfPresent(AirDemandRouteSegmentDO::getArrive, reqVO.getArrive())
                .betweenIfPresent(AirDemandRouteSegmentDO::getFlightDate, reqVO.getFlightDate())
                .betweenIfPresent(AirDemandRouteSegmentDO::getArriveDate, reqVO.getArriveDate())
                .likeIfPresent(AirDemandRouteSegmentDO::getDepartTerminal, reqVO.getDepartTerminal())
                .likeIfPresent(AirDemandRouteSegmentDO::getArriveTerminal, reqVO.getArriveTerminal())
                .likeIfPresent(AirDemandRouteSegmentDO::getAirModel, reqVO.getAirModel())
                .eqIfPresent(AirDemandRouteSegmentDO::getStop, reqVO.getStop())
                .likeIfPresent(AirDemandRouteSegmentDO::getStopAirportNo, reqVO.getStopAirportNo())
                .likeIfPresent(AirDemandRouteSegmentDO::getStopTerminal, reqVO.getStopTerminal())
                .eqIfPresent(AirDemandRouteSegmentDO::getShare, reqVO.getShare())
                .likeIfPresent(AirDemandRouteSegmentDO::getBaggageWeight, reqVO.getBaggageWeight())
                .betweenIfPresent(AirDemandRouteSegmentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AirDemandRouteSegmentDO::getId));
    }

    default List<AirDemandRouteSegmentRespVO> selectByDemandId(Long demandId) {
        return selectJoinList(AirDemandRouteSegmentRespVO.class, new MPJLambdaWrapperX<AirDemandRouteSegmentDO>()
                .eq(AirDemandRouteSegmentDO::getDemandId, demandId)
                .selectAll(AirDemandRouteSegmentDO.class)
        );
    }

    default int deleteByDemandId(Long demandId) {
        return delete(AirDemandRouteSegmentDO::getDemandId, demandId);
    }
}
